#include "RectangleOverlayFilter.h"
#include <opencv2/imgproc/imgproc.hpp>

RectangleOverlayFilter::RectangleOverlayFilter(const cv::Scalar &color, const int &thickness, const int &style, const int &shift) :
	Filter(2, 1),
	color(color),
	thickness(thickness),
	style(style),
	shift(shift)
{
	
}


RectangleOverlayFilter::~RectangleOverlayFilter(void)
{
}

void RectangleOverlayFilter::Process()
{
	if (inputs[0]->channels() == 3)
	{
		outputs[0] = inputs[0]->clone();
	}
	else if (inputs[0]->channels() == 1)
	{
		cv::cvtColor(*inputs[0], outputs[0], CV_GRAY2BGR);
	}

	for (int i = 0; i < inputs[1]->rows; ++i)
	{
		cv::Rect rect;
		rect.x = inputs[1]->at<int>(i, 0);
		rect.y = inputs[1]->at<int>(i, 1);
		rect.width = inputs[1]->at<int>(i, 2);
		rect.height = inputs[1]->at<int>(i, 3);

		cv::rectangle(outputs[0], rect, color, thickness, style, shift);
	}
}

void RectangleOverlayFilter::ProcessInvalid()
{
	outputs[0] = inputs[0]->clone();
}
